import React, { Component } from 'react'
import axios from 'axios'
import PubSub from 'pubsub-js'
export default class search extends Component {
    search=()=>{
     //获取文本框的值
     const value=this.keyWordElement.value
     //发布订阅
     PubSub.publish("gitxx",{isFirst:false,isLoading:true})
     //发送网络请求
		axios.get(`/api1/search/users2?q=${value}`).then(
			response => {
                console.log(response.data.items)
				//请求成功后通知App更新状态
				
                PubSub.publish('gitxx',{isLoading:false,users:response.data.items})
			},
			error => {
				//请求失败后通知App更新状态
				
                PubSub.publish('gitxx',{isLoading:false,err:error.message})
			}
		)
    }
    render() {
        return (
           <section className="jumbotron">
               <h3 className="jumbotron-heading">搜索github用户</h3>
               <div>
                   <input type='text' placeholder="输入关键词点击搜索" ref={c=>this.keyWordElement=c}/>&nbsp;
                   <button onClick={this.search}>搜索</button>
               </div>
           </section>
        )
    }
}
